<template>
  <div class="content">
    <div class="top">
      <span class="logo">我的云盘</span>
      <!-- <div class="search">搜索框</div> -->
      <div class="info">
        <img :src="photo" />
        <el-popover placement="top-start" width="270" trigger="hover">
          <div class="txxx">
            <div class="head">
              <img :src="photo" />
              <div class="xx">
                <span>{{ username }}</span>
                <span>{{ email }}</span>
              </div>
            </div>
            <el-button type="danger" @click="outloginFn">退出登录</el-button>
          </div>
          <el-button type="text" slot="reference">{{ username }}</el-button>
        </el-popover>
      </div>
    </div>
    <div class="main">
      <div class="left">
        <nav>
          <div
            :class="[active == it.name ? 'active' : '', 'item']"
            v-for="it in list"
            :key="it.name"
            @click="toPush(it)"
          >
            <!-- v-if="it.diction.indexOf(auth) > -1" -->
            <template>
              <span><i :class="it.meta.icon"></i></span>
              <span>{{ it.title }}</span>
            </template>
          </div>
        </nav>
      </div>
      <div class="rigth">
        <router-view />
      </div>
    </div>
  </div>
</template>

<script>
import { mapMutations, mapGetters, mapState } from "vuex";
export default {
  name: "layout",
  data() {
    return {
      active: this.$route.name,
    };
  },

  computed: {
    ...mapState(["username", "email", "auth", "photo"]),
    list() {
      return this.$router.options.routes[1].children;
    },
  },
  methods: {
    ...mapMutations(["outlogin"]),
    outloginFn() {
      this.outlogin(this);
    },
    toPush(item) {
      this.$router.push(`/${item.path}`);
      this.active = item.name;
    },
  },
};
</script>

<style lang="scss" scoped>
.content {
  width: 100vw;
  height: 100vh;
  background-color: #f2f4f8;
}
.top {
  height: 60px;
  background-color: #fff;
  box-shadow: 0 5px 10px -5px #d8d8d8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .logo {
    width: 10vw;
    height: 100%;
    line-height: 60px;
    font-size: 20px;
    font-weight: bold;
  }
  .info {
    padding-right: 100px;
    display: flex;
    align-items: center;
    cursor: pointer;
    img {
      width: 30px;
      height: 30px;
      border-radius: 50%;
      padding: 0 10px;
    }
  }
}
.txxx {
  display: flex;
  flex-direction: column;
  .head {
    display: flex;
    align-items: center;
    background-image: linear-gradient(
      159deg,
      #b58c58 0,
      #f1cd92 51%,
      #e6c187 64%,
      #b68a57 100%
    );
    margin-bottom: 10px;
  }
  color: #000;

  img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    padding: 10px;
  }
  .xx {
    display: flex;
    flex-direction: column;
  }
}
.main {
  margin-top: 20px;
  display: flex;
  .left {
    margin-left: 20px;
    width: 10vw;
    nav {
      .item {
        padding: 15px 10px;
        font-weight: bold;
        cursor: pointer;

        span {
          margin: 0 5px;
        }
        &:hover {
          color: #2777f8;
          background-color: #fff;
        }
      }

      .active {
        color: #2777f8;
        background-color: #fff;
      }
    }
  }
  .rigth {
    text-align: left;
    flex: 1;
    height: calc(100vh - 120px);
    background-color: #fff;
    padding: 20px;
    overflow-y: scroll;
  }
}
div::-webkit-scrollbar {
  width: 10px;
  height: 10px;
  /**/
}
div::-webkit-scrollbar-track {
  background: rgb(239, 239, 239);
  border-radius: 2px;
}
div::-webkit-scrollbar-thumb {
  background: #bfbfbf;
  border-radius: 10px;
}
div::-webkit-scrollbar-thumb:hover {
  background: #2777f8;
}
div::-webkit-scrollbar-corner {
  background: #179a16;
}
</style>
